package com.openspring.framework.service;

import java.io.Serializable;
import java.util.List;
import com.openspring.framework.dao.GenericDAO;

public abstract class AbstractGenericService<T, ID extends Serializable> implements GenericService<T, ID> {

	//private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AbstractGenericService.class);
	
	private GenericDAO<T, ID> genericDAO;
	
	public void setGenericDAO(GenericDAO<T, ID> genericDAO) {
		this.genericDAO = genericDAO;
	}

	@Override
	public void create(T entity) {
		genericDAO.insert(entity);
	}

	@Override
	public void remove(ID id) {
		genericDAO.delete(id);
	}

	@Override
	public void remove(ID[] ids) {
		genericDAO.batchDelete(ids);
	}

	@Override
	public void modify(T entity) {
		genericDAO.update(entity);
	}

	@Override
	public T load(ID id) {
		return genericDAO.load(id);
	}

	@Override
	public List<T> findAll() {
		return genericDAO.queryAll();
	}
	
	@Override
	public List<T> find(String sql, Object... values) {
		return genericDAO.query(sql, values);
	}
	
	@Override
	public List<T> findWhere(String whereSql, Object... values) {
		return genericDAO.queryWhere(whereSql, values);
	}

	@Override
	public int getTotalCount() {
		return genericDAO.getTotalCount();
	}

	@Override
	public int getTotalCount(String whereSql, Object... values) {
		return genericDAO.getTotalCount(whereSql, values);
	}
}
